#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //

    //
    t=new QThread(this);
    looper = new  MyEventLooper();
    QObject::connect(looper,&MyEventLooper::processGoSig, this, Widget::rcvProcessGoSig);

    looper->moveToThread(t);
    t->start();
}

Widget::~Widget()
{
    t->terminate();
    delete ui;
}


void Widget::on_btnCho_clicked()
{
    QString filename=QFileDialog::getOpenFileName(this, "选择文件", "C:/Users/zhuorui/Desktop");
    qDebug() << "filename:" << filename;
    ui->label->setText(filename);
}

void Widget::on_btnLoad_clicked()
{
    //加载文件
    //    QFile file(ui->label->text());
    //    if(!file.open(QFile::ReadOnly)){
    //        qDebug() << "文件读取失败";
    //        return ;
    //    }
    //    file.close()
    //读取文件中的内容
    looper->startReadFile(ui->label->text());
}

void Widget::rcvProcessGoSig(int percent)
{
    qDebug() << "rcvProcessGoSig。 percent="<<percent;
    ui->slider->setValue(percent);
    if(percent >= 100){
        QMessageBox::information(this,"提示","文件读取完成");
    }
}
